﻿using BarrageGameAssistant.Core.Configs;
using BarrageGameAssistant.Core.Enums;
using KMSimulator.Model;
using M56.Core.Utils;
using Newtonsoft.Json;
using System.Drawing;

namespace BarrageGameAssistant.Core.Model
{
    public class Scene
    {
        /// <summary>
        /// 场景ID
        /// </summary>
        public string Id { get; set; } = Guid.NewGuid().ToString();

        /// <summary>
        /// 排序索引号
        /// </summary>
        public int Index { get; set; }

        /// <summary>
        /// 场景名称
        /// </summary>
        public string Name { get; set; } = string.Empty;

        /// <summary>
        /// 场景尺寸
        /// </summary>
        public Size SceneResolutionRatio { get; set; } = new Size(1080, 1920);

        /// <summary>
        /// 图片实际大小
        /// </summary>
        public Size ImageRealResolutionRatio;

        /// <summary>
        /// 场景类型
        /// </summary>
        public GameSceneType SceneType { get; set; }

        /// <summary>
        /// 阈值
        /// </summary>
        public double Threshold { get; set; } = 0.65f;

        /// <summary>
        /// 停留延时
        /// </summary>
        public int StopDuration { get; set; } = 10000;

        /// <summary>
        /// 场景识别定义数据
        /// </summary>
        public List<SceneMatchData> SceneMatchDatas { get; set; }

        /// <summary>
        /// 过程数据源定义
        /// </summary>
        public List<ProcessMatchData> ProcessMatchDatas { get; set; }

        /// <summary>
        /// 鼠键模拟动作集合
        /// </summary>
        public List<KMActionBase> Actions { get; set; }

        /// <summary>
        /// 场景话术
        /// </summary>
        public List<LanguageScript> Scripts { get; set; }

        public Scene()
        {
            SceneMatchDatas = [];
            ProcessMatchDatas = [];
            Actions = [];
            Scripts = [];
        }

        /// <summary>
        /// 克隆场景
        /// </summary>
        /// <returns></returns>
        public Scene? Clone()
        {
            try
            {
                List<JsonConverter> JsonConverters =
                    [
                        new KMActionConverter()
                    ];
                var jsonStr = JsonUtils.ToJson(this, JsonUtils.DefaultSetting());
                var data = JsonUtils.FromJson<Scene>(jsonStr, false, [.. JsonConverters]);

                return data;
            }
            catch (Exception)
            {
                return null;
            }
        }

        public override string ToString()
        {
            return $"";
        }
    }
}
